/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package exercises.day04.pt01.bean;

import exercises.day04.pt02.Exception.*;
import java.io.Serializable;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Student
 */
public class AccountRegistration implements Serializable {

    private Integer regId;
    private String fName;
    private String lName;
    private String address;
    private String accountType;
    private Double income;
    private String phone;

    public AccountRegistration(String regId, String fName, String lName, String address, String accountType, String income, String phone) throws AccountTypeIsInvalidException, AccountTypeIsNullException, AddressIsNullException, AddressLenghtLessThan25Exception, FirstNameIsNullException, LastNameIsNullException, NameIsJohnDoeException, AnnualIncomeIsNullException, AnnualIncomeValidationException, PhoneIsNullException, PhoneLenghtLessThan7Exception, RegisterIdIsNotIntegerException, IncomeIsNotDoubleException {


        this.setAccountType(accountType);
        this.setAddress(address);
        this.setRegId(regId);
        this.setfName(fName);
        this.setlName(lName);
        this.setIncome(income);
        this.setPhone(phone);

    }

    private void setRegId(String regId) throws RegisterIdIsNotIntegerException {

        if (regId == null) {
            try {
                throw new RegisterIdIsNullException();
            } catch (RegisterIdIsNullException ex) {
                Logger.getLogger(AccountRegistration.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else {
            try {
                this.regId = Integer.valueOf(regId);
            } catch (NumberFormatException ex) {
                throw new RegisterIdIsNotIntegerException();
            }

        }

    }

    private void setAccountType(String accountType) throws AccountTypeIsInvalidException, AccountTypeIsNullException {
        if (!(accountType.equals("Current") || accountType.equals("Savings") || accountType.equals("Fixed Deposit"))) {

            throw new AccountTypeIsInvalidException();

        } else if (accountType == null || accountType.equals("")) {
            throw new AccountTypeIsNullException();
        } else {
            this.accountType = accountType;
        }
    }

    private void setAddress(String address) throws AddressIsNullException, AddressLenghtLessThan25Exception {
        if (address == null || address.equals("")) {

            throw new AddressIsNullException();

        } else if (address.length() < 25) {
             System.out.println(address.length());
            throw new AddressLenghtLessThan25Exception();
           
        } else {
            this.address = address;
        }
    }

    private void setIncome(String income) throws AnnualIncomeIsNullException, AnnualIncomeValidationException, IncomeIsNotDoubleException {
        if (income == null) {
            throw new AnnualIncomeIsNullException();
        } else {
            try {
                Double value = Double.valueOf(income);
                if (value <= 0 || value > 750000) {
                    throw new AnnualIncomeValidationException();
                } else {
                    this.income = value;
                }
            } catch (NumberFormatException ex) {
                throw new IncomeIsNotDoubleException();
            }
        }
    }

    private void setfName(String fName) throws FirstNameIsNullException {

        if (fName == null || fName.equals("")) {
            throw new FirstNameIsNullException();
        } else {
            this.fName = fName;
        }
    }

    private void setlName(String lName) throws LastNameIsNullException, NameIsJohnDoeException {
        if (lName == null || lName.equals("")) {
            throw new LastNameIsNullException();
        } else if (fName.equals("John") && lName.equals("Doe")) {
            throw new NameIsJohnDoeException();
        } else if (fName.equals("Jane") && lName.equals("Doe")) {
            throw new NameIsJohnDoeException();
        } else {
            this.lName = lName;
        }
    }

    private void setPhone(String phone) throws PhoneIsNullException, PhoneLenghtLessThan7Exception {


        if (phone == null || phone.equals("")) {
            throw new PhoneIsNullException();
        } else if (phone.length() <= 7) {
            throw new PhoneLenghtLessThan7Exception();
        } else {
            this.phone = phone;
        }

    }

    /**
     * ********************* GETTTTERRRRR
     * *********************************************
     */
    public String getAddress() {
        return address;
    }

    public String getfName() {
        return fName;
    }

    public Double getIncome() {
        return income;
    }

    public String getlName() {
        return lName;
    }

    public String getPhone() {
        return phone;
    }

    public Integer getRegId() {
        return regId;
    }

    public String getAccountType() {
        return accountType;
    }

    @Override
    public String toString() {
        return  regId + ", " + fName + ", " + lName + ", " + address + ", " + accountType + ", " + income + ", " + phone ;
    }
    
    
    
    
}
